import tkinter as tk
from datetime import datetime
from tkinter import ttk

from Common.CommonUtils import CommonUtils
from view.MessagePage import MessagePage
from view.PrintPage import PrintPage


class MainPage(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title("摸🐟")
        self.iconbitmap(r"config/favicon.ico")

        # 设置窗口大小
        self.geometry("929x485")

        # 创建Notebook控件
        self.notebook = ttk.Notebook(self)
        self.notebook.pack(fill="both", expand=True, padx=10, pady=10)

        # 创建并添加三个页面
        self.page1 = TimePage(self.notebook)
        self.notebook.add(self.page1, text="主界面")

        self.page2 = MessagePage(self.notebook)
        self.notebook.add(self.page2, text="信息生成")

        self.page3 = PrintPage(self.notebook)
        self.notebook.add(self.page3, text="打印")


class TimePage(tk.Frame):
    def __init__(self, master):
        super().__init__(master)
        self.master = master

        # 设置页面大小
        self.config(width=780, height=580)

        # 获取父窗口（Notebook）的背景色
        # bg_color = self.master.cget("background")

        # 创建一个大字体
        big_font = ("Arial", 48)

        # 创建一个实时更新的时钟标签
        self.clock_label = tk.Label(self, font=big_font, bg="white", anchor="center")
        self.clock_label.pack(pady=100)

        # 创建一行文字标签

        self.text_label = tk.Label(self, text=CommonUtils.ran_message(), font=("Arial", 24), bg="white", anchor="center")
        self.text_label.pack(pady=10)

        # 更新时钟的定时器
        self.update_clock()

    def update_clock(self):
        current_time = datetime.now().strftime("%H:%M:%S")
        self.clock_label.config(text=current_time)
        self.after(1000, self.update_clock)  # 每秒更新一次



